package com.ylxl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ylxl.common.exception.BaseException;
import com.ylxl.common.utils.StringUtils;
import com.ylxl.entity.LaborProtectionSize;
import com.ylxl.entity.request.MateriaCmd;
import com.ylxl.entity.request.MateriaRemove;
import com.ylxl.entity.request.QueryLaborProtectionSize;
import com.ylxl.mapper.LaborProtectionSizeMapper;
import com.ylxl.service.ILaborProtectionSizeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户 业务层处理
 *
 */
@Service
public class LaborProtectionSizeServiceImpl extends ServiceImpl<LaborProtectionSizeMapper, LaborProtectionSize>  implements ILaborProtectionSizeService {
    private static final Logger log = LoggerFactory.getLogger(LaborProtectionSizeServiceImpl.class);

    @Autowired
    private LaborProtectionSizeMapper laborProtectionSizeMapper;


    @Override
    public List<LaborProtectionSize> selectMateriaList(QueryLaborProtectionSize queryLaborProtectionSize){
        LambdaQueryWrapper<LaborProtectionSize> programLambdaQueryWrapper = new LambdaQueryWrapper<>();
        programLambdaQueryWrapper.eq(LaborProtectionSize::getLaborId,queryLaborProtectionSize.getLaborId());
        List<LaborProtectionSize> laborProtectionSizeList = laborProtectionSizeMapper.selectList(programLambdaQueryWrapper);
        return laborProtectionSizeList;
    }

    @Override
    public int insertMateriar(MateriaCmd cmd) {
        LaborProtectionSize laborProtectionSize = new LaborProtectionSize();
        BeanUtil.copyProperties(cmd, laborProtectionSize);//属性拷贝
        return laborProtectionSizeMapper.insert(laborProtectionSize);
    }
    @Override
    public int remove(MateriaRemove remove) {
        if(StringUtils.isEmpty(remove.getLaborId())){
            throw new BaseException("劳保id不能为空!!!");
        }
        LambdaUpdateWrapper<LaborProtectionSize> materiaProgramLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        materiaProgramLambdaUpdateWrapper.eq(LaborProtectionSize::getLaborId,remove.getLaborId());
        return laborProtectionSizeMapper.delete(materiaProgramLambdaUpdateWrapper);
    }

}
